package dao.impl;

import dao.BaseDao;
import dao.OrderItemDao;
import pojo.OrderItem;

import java.util.List;

/**
 * @author Wxt
 * @create 2022-02-11 21:06
 */
public class OrderItemDaoImpl extends BaseDao implements OrderItemDao {
    @Override
    public int saveOrderItem(OrderItem orderItem) {
        String sql = "insert into t_order_item(id,name,count,price,total_price,order_id) values(?,?,?,?,?,?)";
        return update(sql, orderItem.getId(),orderItem.getName(),orderItem.getCount(),orderItem.getPrice(),orderItem.getTotalPrice(),orderItem.getOrderId());
    }

    @Override
    public List<OrderItem> queryOrderItemsByOrderId(String orderId) {
        String sql = "select id,name,count,price,total_price as totalPrice,order_id as orderId from t_order_item where order_id = ?";
        return queryForList(OrderItem.class, sql, orderId);
    }
}
